#include "config.h"
#include <rapidjson/document.h>
#include <iostream>
#include <fstream>


bool Config::ReadConfigFile(const std::string& cfg_file)
{
    std::ifstream ifs(cfg_file);
    if(!ifs.is_open())
    {
        std::cout << "open config file failed !" << std::endl;
        return false;
    }

    std::string json_content((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
    ifs.close();

    rapidjson::Document dom;
    dom.Parse<rapidjson::ParseFlag::kParseDefaultFlags>(json_content.c_str());
    if(dom.HasParseError())
    {
        std::cout << "parse config file failed !" << std::endl;
        return false;
    }

    gps_file_ = dom["file-gps-aligned"].GetString();
    img_path_ = dom["dir-image"].GetString();
    deep_learning_lane_path = dom["dir-lane"].GetString();
    deep_learning_sign_path = dom["dir-sign"].GetString();
    cam_cfg_file = dom["cam_cfg"].GetString();
    return true;
}